package Market.CBD;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.ArrayList;

import com.google.protobuf.Message;

import Market.CBD.CBDMarketDataOuterClass.CBDMarketData;
import Market.CBD.CBDMarketDataOuterClass.CBDMarketData.Builder;

enum MDType {
    R, unknow
}

enum MDSubType {
    unknow
}

enum EqQuoteType {
    unknow
}

enum TradeMethod {
    unknow;
}

enum MarketIndicator {
    unknow;
}

public class ReadFromFile {
    // public double lowPx;
    // public Date eqDate;
    // public int eqTime;
    // public double highPx;
    // public MDType mdType;
    // public double openPx;
    // public int eqMarket;
    // public double lastYield;
    // public double latestPrx;
    // public MDSubType mdSubType;
    // public double openYield;
    // public double wgtAvgPrx;
    // public double changeOver;
    // public int securityID;
    // public EqQuoteType eqQuoteType;
    // public double lowestYield;
    // public double preClosePrx;
    // public TradeMethod tradeMethod;
    // public int tradeVolume;
    // public double wgtAvgYield;
    // public String eqSecurityID;
    // public double highestYield;
    // public double preWgtAvgPrx;
    // public Date transactTime;
    // public double preCloseYield;
    // public double preWgtAvgYield;
    // public MarketIndicator marketIndicator;
    public ArrayList<CBDMarketData> CBDMarkets=new ArrayList<>();
    public void setColVal(String[] colVals){
        Builder builder = CBDMarketData.newBuilder();
        builder.setLowPx(Double.valueOf(colVals[0]));
        builder.setEqDate(colVals[1]);
        builder.setEqTime(Double.valueOf(colVals[2]));
        builder.setHighPx(Double.valueOf(colVals[3]));
        builder.setMdType(colVals[4]);
        builder.setOpenPx(Double.valueOf(colVals[5]));
        builder.setEqMarket(Double.valueOf(colVals[6]));
        builder.setLastYield(Double.valueOf(colVals[7]));
        builder.setLatestPrx(Double.valueOf(colVals[8]));
        builder.setMdSubType(colVals[9]);
        builder.setOpenYield(Double.valueOf(colVals[10]));
        builder.setWgtAvgPrx(Double.valueOf(colVals[11]));
        builder.setChangeOver(Double.valueOf(colVals[12]));
        builder.setSecurityID(Double.valueOf(colVals[13]));
        builder.setEqQuoteType(colVals[14]);
        builder.setLowestYield(Double.valueOf(colVals[15]));
        builder.setPreClosePrx(Double.valueOf(colVals[16]));
        builder.setTradeMethod(colVals[17]);
        builder.setTradeVolume(Double.valueOf(colVals[18]));
        builder.setWgtAvgYield(Double.valueOf(colVals[19]));
        builder.setEqSecurityID(colVals[20]);
        builder.setHighestYield(Double.valueOf(colVals[21]));
        builder.setPreWgtAvgPrx(Double.valueOf(colVals[22]));
        builder.setTransactTime(colVals[23]);
        builder.setPreCloseYield(Double.valueOf(colVals[24]));
        builder.setPreWgtAvgYield(Double.valueOf(colVals[25]));
        builder.setMarketIndicator(colVals[26]);
        CBDMarkets.add(builder.build());
    }

    public void readFromCsvFile(String path){
        String line;
        String[] colVal;
        String csvSplitBy=",";
        try (BufferedReader br = new BufferedReader(new FileReader(path))){
            if((line=br.readLine())==null)return;
            while((line = br.readLine())!=null){
                line = line.replace("\"", "");
                colVal = line.split(csvSplitBy);
                setColVal(colVal);
            }
        } catch (Exception e) {
            //TODO: handle exception
            System.err.print(e);
        }
    }

    public static void main(String[] args) {
        System.out.println("hello world");
        Builder builder = CBDMarketData.newBuilder();
        builder.setPreClosePrx(1.0);

        Message CBDMarket = builder.build();
        System.out.println(CBDMarket);
    }

}
